<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>报告列表</title>
    <%- include('../../../_global/baseLibs') %>
    <link rel="stylesheet" href="/static/css/jkda/page-main.css"/>
    <script src="/static/js/common.js"></script>

    <style type="text/css">
        html, body {
            width: 100%;
            height: 100%;
            margin: 0px;
        }
        body {
            transform: perspective(1400px) matrix3d(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
            transform-style: preserve-3d;
        }
    </style>

</head>




<body>
<div class="tab-box">
    <span class="gray-line"></span>
    <ul id="ListTab">
        <li><a>检验记录</a></li>
        <li><a>检查记录</a></li>
    </ul>
</div>
<div id="ListTabBox">
    <div class="tab active">
        <div class="mz-list"  >
            <ul id= "jyjl" >
            </ul>
        </div>
    </div>
    <div class="tab">
        <div class="mz-list">
            <ul id="jcjl"></ul>
        </div>
    </div>
</div>
</body>
<script type="text/html" id="jyItem">
    <li>
        <a class="li-box">
            <div class="black-block">
                <span>检验时间：</span>
                <span field="bgsj">2018年3月27日</span>
            </div>
            <div class="gray-block">
                <span>医&emsp;&emsp;院：</span>
                <span field="yymc">测试医院</span>
            </div>
            <div class="gray-block">
                <span>检验类型：</span>
                <span field="jyjclx">检验类型</span>
            </div>
            <div class="gray-block">
                <span>检验项目：</span>
                <span field="jyjcxm">检验项目</span>
            </div>
        </a>
    </li>
</script>
<script type="text/html" id="jcItem">
    <li>
        <a class="li-box">
            <div class="black-block">
                <span>检查时间：</span>
                <span field="bgsj">2018年3月27日</span>
            </div>
            <div class="gray-block">
                <span>医&emsp;&emsp;院：</span>
                <span field="yymc">测试医院</span>
            </div>
            <div class="gray-block">
                <span>检查类型：</span>
                <span field="jyjclx">检查类型</span>
            </div>
            <div class="gray-block">
                <span>检查项目：</span>
                <span field="jyjcxm">检查项目</span>
            </div>
        </a>
    </li>
</script>
<script type="text/javascript">
    var api = "/api";

    var page_reportList = (function($, page_reportList) {

        function initView(){
            $('#ListTab').find('li').click(function(){
                $(this).addClass('active').siblings().removeClass('active');
                $('#ListTabBox').find('.tab').hide().eq($(this).index()).show(10, function(){
                    var id = $(this).find('ul').attr("id");
                    var length = $(this).find('li').length;
                    if(length == 0){
                        if('jyjl' == id){
                            page_reportList.queryJyReport();
                        }else if('jcjl' == id){
                            page_reportList.queryJcReport();
                        }
                    }
                });
            });
            $("#jyjl").on("click", "li", function(){
                var item = $(this).data("jyItem");

                $.pageSwitch.goToUrl("searchReport","jyreportDetail","cardId="+item["rNo"]+"&medicalOrgId="+item["yydm"]+"&rid="+item["bgid"]+"&cardDate="+item["bgsj"].substr(0,10)+"&yymc="+item["yymc"]);
            });
            $("#jcjl").on("click", "li", function(){
                var item = $(this).data("jcItem");
                $.pageSwitch.goToUrl("searchReport","jcreportDetail","id="+item["examNo"]+"&serialNum="+item["serialNum"]
                    +"&applyTime="+item["bgsj"].substr(0,10)+"&medicalOrgId="+item["yydm"]+"&yymc="+item["yymc"])
            })

            $("#ListTab").find("li:eq(0)").trigger('click');
        }

        function indata(){
            var queryParams = StoreCache.getCache("searchInfo");
            var obj ={
                idCard:queryParams.patientCardId,//"510123199101273421",
                medicalOrgId:queryParams.hosCode,//"451135959"
                startDate:queryParams.beginTime,
                endDate:queryParams.endTime
            }
            $("body").data("queryParams", obj);
        }

        function queryJyReport(){
            var params = $("body").data("queryParams");
            var url = api + "/gzd/jyjc/queryJyReport";
            $.QuickRemote.AjaxJson({
                funcName:url
                ,callback:page_reportList.queryJyReportHandler
                ,params:params});
        }
        function queryJyReportHandler(result){
            if(result != null && result.length > 0){
                $.each(result, function(index, item){
                    var item1 = page_reportList.createJyjlItem(item);
                    $("#jyjl").append(item1);
                })
            }
        }
        /*创建检验记录*/
        function createJyjlItem(data){
            var jyItem = $($("#jyItem").html());
            var bgsj = data["bgsj"];
            if(!StringUtils.isEmpty(bgsj)){
                bgsj = bgsj.split(" ")[0];
            }
            jyItem.find("span[field='bgsj']").html(bgsj);
            var yymc = data["yymc"];
            jyItem.find("span[field='yymc']").html(getLable(yymc));
            var jyjclx = data["jyjclx"];
            jyItem.find("span[field='jyjclx']").html(getLable(jyjclx));
            var jyjcxm = data["jyjcxm"];
            jyItem.find("span[field='jyjcxm']").html(getLable(jyjcxm));
            jyItem.data("jyItem", data);
            return jyItem;
        }

        function queryJcReport(){
            var params = $("body").data("queryParams");
            var url = api + "/gzd/jyjc/queryJcReport";
            // var  params={
            //      idCard:"510123199101273421",
            //      medicalOrgId:"451135959",
            //      startDate:"2017-01-01",
            //      endDate:"2017-12-12"
            //  }
            $.QuickRemote.AjaxJson({
                funcName:url
                ,callback:page_reportList.queryJcReportHandler
                ,params:params});
        }
        function queryJcReportHandler(result){
            if(result != null && result.length > 0){
                $.each(result, function(index, item){
                    var item1 = page_reportList.createJcjlItem(item);
                    $("#jcjl").append(item1);
                })
            }
        }
        /*创建检查记录*/
        function createJcjlItem(data){
            var jcItem = $($("#jcItem").html());
            var bgsj = data["bgsj"];
            if(!StringUtils.isEmpty(bgsj)){
                bgsj = bgsj.split(" ")[0];
            }
            jcItem.find("span[field='bgsj']").html(bgsj);
            var yymc = data["yymc"];
            jcItem.find("span[field='yymc']").html(getLable(yymc));
            var jyjclx = data["jyjclx"];
            jcItem.find("span[field='jyjclx']").html(getLable(jyjclx));
            var jyjcxm = data["jyjcxm"];
            jcItem.find("span[field='jyjcxm']").html(getLable(jyjcxm));
            jcItem.data("jcItem", data);
            return jcItem;
        }


        function getLable(str){
            if(str.length > 12){
                return str.substring(0, 12) + "...";
            }
            return str;
        }
        var cfg_def = {
            initView: initView,
            indata: indata,
            queryJyReport: queryJyReport,
            queryJyReportHandler: queryJyReportHandler,
            createJyjlItem: createJyjlItem,
            queryJcReport: queryJcReport,
            queryJcReportHandler: queryJcReportHandler,
            createJcjlItem: createJcjlItem,
        }

        page_reportList.init = function(cfg){
            $.extend(page_reportList, cfg_def, cfg);
            page_reportList.initView();
            page_reportList.indata();

        }

        return page_reportList;
    })(jQuery, {});

</script>
</html>